/***************************************************************
 * Name:      TestWx1Main.cpp
 * Purpose:   Code for Application Frame
 * Author:    Roman Navarro (rnavarro@robotnik.es)
 * Created:   2012-02-16
 * Copyright: Roman Navarro ()
 * License:
 **************************************************************/

#include "TestWx1Main.h"
#include <wx/msgdlg.h>
#include "TurtleSimDialog.h"
#include "TestDialog1.h"
#include "ros/ros.h"
#include "std_msgs/String.h"


//(*InternalHeaders(TestWx1Frame)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}

//(*IdInit(TestWx1Frame)
const long TestWx1Frame::ID_BUTTON1 = wxNewId();
const long TestWx1Frame::ID_TEXTCTRL1 = wxNewId();
const long TestWx1Frame::ID_CHECKBOX1 = wxNewId();
const long TestWx1Frame::ID_PANEL1 = wxNewId();
const long TestWx1Frame::idMenuQuit = wxNewId();
const long TestWx1Frame::idMenuAbout = wxNewId();
const long TestWx1Frame::id_NewDialog = wxNewId();
const long TestWx1Frame::ID_STATUSBAR1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(TestWx1Frame,wxFrame)
    //(*EventTable(TestWx1Frame)
    //*)
END_EVENT_TABLE()

TestWx1Frame::TestWx1Frame(wxWindow* parent,wxWindowID id)
{
    //(*Initialize(TestWx1Frame)
    wxMenuItem* MenuItem2;
    wxMenuItem* MenuItem1;
    wxBoxSizer* BoxSizer2;
    wxMenu* Menu1;
    wxBoxSizer* BoxSizer1;
    wxMenuBar* MenuBar1;
    wxMenu* Menu2;

    Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
    SetClientSize(wxSize(339,20));
    BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
    Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
    BoxSizer2 = new wxBoxSizer(wxVERTICAL);
    Button1 = new wxButton(Panel1, ID_BUTTON1, _("Connect"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
    BoxSizer2->Add(Button1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    TextCtrl1 = new wxTextCtrl(Panel1, ID_TEXTCTRL1, _("Text"), wxDefaultPosition, wxSize(60,29), 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
    BoxSizer2->Add(TextCtrl1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    CheckBox1 = new wxCheckBox(Panel1, ID_CHECKBOX1, _("Label"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX1"));
    CheckBox1->SetValue(false);
    BoxSizer2->Add(CheckBox1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Panel1->SetSizer(BoxSizer2);
    BoxSizer2->Fit(Panel1);
    BoxSizer2->SetSizeHints(Panel1);
    BoxSizer1->Add(Panel1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
    SetSizer(BoxSizer1);
    MenuBar1 = new wxMenuBar();
    Menu1 = new wxMenu();
    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);
    MenuBar1->Append(Menu1, _("&File"));
    Menu2 = new wxMenu();
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("Help"));
    Menu3 = new wxMenu();
    Menu4 = new wxMenuItem(Menu3, id_NewDialog, _("New Dialog"), wxEmptyString, wxITEM_NORMAL);
    Menu3->Append(Menu4);
    MenuBar1->Append(Menu3, _("New.."));
    SetMenuBar(MenuBar1);
    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[1] = { -1 };
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
    SetStatusBar(StatusBar1);
    BoxSizer1->SetSizeHints(this);

    Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&TestWx1Frame::OnButton1Click);
    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&TestWx1Frame::OnQuit);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&TestWx1Frame::OnAbout);
    Connect(id_NewDialog,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&TestWx1Frame::OnMenuNewDialogSelected);
    //*)

    //TEST
    //rosif = new RosInterface();
}

TestWx1Frame::~TestWx1Frame()
{
    //(*Destroy(TestWx1Frame)
    //*)
}

void TestWx1Frame::OnQuit(wxCommandEvent& event)
{
    Close();
}

void TestWx1Frame::OnAbout(wxCommandEvent& event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}

void TestWx1Frame::OnButton1Click(wxCommandEvent& event)
{

    TurtleSimDialog *dialog = new TurtleSimDialog(this);
    dialog->Start();
    dialog->Show();
    //

    //rosif->Start();

}

void TestWx1Frame::OnMenuNewDialogSelected(wxCommandEvent& event)
{
    TestDialog1 *dialog = new TestDialog1(this);

    dialog->Show();
}
